package com.zr.java8.pattern.observer.impl;

import com.zr.java8.pattern.observer.Observer;
import com.zr.java8.pattern.observer.Subject;

import java.util.ArrayList;
import java.util.List;

public class Feed implements Subject {

    private final List<Observer> observers = new ArrayList<>();
    @Override
    public void registerObserver(Observer observer) {
        this.observers.add(observer);
    }

    @Override
    public void notifyObservers(String tweet) {
        this.observers.forEach(observer -> observer.notice(tweet));
    }

    public static void main(String[] args) {
        Feed f = new Feed();
        f.registerObserver(new NYTimesObserver());
        f.registerObserver(new GuardianObserver());
        f.notifyObservers("the queen said her favourite book is Java 8 in Action!");
    }
}
